/**
 * @program: LeetCode
 * @description: LeetCode : 面试题 16.17. 连续数列
 * @author: WXY
 * @create: 2023-01-07 15:26
 * @Version 1.0
 **/
public class Num16_17_maxSubArray {
    public int maxSubArray(int[] nums) {
        int cur = nums[0];
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            cur += nums[i];
            max = Math.max(max, cur);
            cur = cur > 0 ? cur : 0;
        }
        return max;
    }
}
